package cn.cs.controller;

import cn.cs.common.Dto;
import cn.cs.common.DtoUtil;
import cn.cs.service.RepairBbsService;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/repairBbs")
public class RepairBbsController {



    @Resource
    private RepairBbsService service;

    /**
     * 分页查询帖子列表
     * @param pageNumber
     * @param pageSize
     * @param title
     * @param type
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/csPlatform/getRepairBbsByPage")
    @ResponseBody
    public Dto getRepairBbsTypeByPage(Integer pageNumber, Integer pageSize, String title, String type) throws Exception {
        Map<String, Object> param = new HashMap<>();
        param.put("title", title);
        param.put("type", type);
        return DtoUtil.returnSuccess("获取成功", service.queryRepairBbsPageByMap(param, pageNumber, pageSize));
    }

    /**
     * 查看帖子详情
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/p/getBBSDetails")
    @ResponseBody
    public Dto getBBSDetails(String id) throws Exception {
        return service.getBBSDetails(id);
    }

    /**
     * 官方发帖
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/csPlatform/releaseBbsAuthority")
    @ResponseBody
    @Transactional
    public Dto releaseBbsAuthority(HttpServletRequest request) throws Exception {
        return service.releaseBbsAuthority(request);
    }

    /**
     * 官方回帖
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/csPlatform/replyBbsAuthority")
    @ResponseBody
    @Transactional
    public Dto replyBbsAuthority(HttpServletRequest request) throws Exception {
        return service.replyBbsAuthority(request);
    }

    /**
     * 设置帖子推荐
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/csPlatform/updateBBSRecommend")
    @ResponseBody
    @Transactional
    public Dto updateBBSRecommend(HttpServletRequest request) throws Exception {
        return service.updateBBSRecommend(request);
    }


}
